/**
 * 查找最长字典子串
 * @param {string} s
 * @param {string[]} dictionary
 * @return {string}
 */
var findLongestWord = function(s, dictionary) {
  let charArr = [];
  // 遍历字典
  dictionary.forEach(word => {
    let chars = word.split('');
    // 判断字符是否在字符串内，先排除一部分
    let allIn = chars.filter(char => {
      return s.indexOf(char) !== -1;
    })
    if(allIn.length === chars.length) {
      charArr.push(word)
    }
  })
  charArr.sort(function(a,b) {
    return b.length - a.length;
  })
  console.log(charArr)
  return charArr[0];
};

console.log(findLongestWord('abpcplea', ["ale","apple","monkey","plea"]));